//
//  ResultViewController.m
//  体育
//
//  Created by liujianlong on 2022/10/24.
//

#import "ResultViewController.h"
#import "ResultHeader.h"
#import "ResultCell.h"

@interface ResultViewController ()
@property (nonatomic, strong) NSArray *array;
@property (nonatomic, assign) NSInteger stamp;
@end

@implementation ResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI{
    self.tableViewStyle = UITableViewStyleGrouped;
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.tableView registerNib:[ResultCell nib] forCellReuseIdentifier:[ResultCell ID]];
    self.tableView.c_edges.equalTo(self.view).coffset(UIEdgeInsetsMake(0, 0, 0, 0));
    self.stamp = [[NSDate currentTimeStamp:@"yyyy-MM-dd"] integerValue];
}

- (void)setStamp:(NSInteger)stamp{
    _stamp = stamp;
    BOOL finish = [self.title isEqualToString:LS(@"赛果")];
    [DataTool find:self.isbastball finish:finish stamp:stamp complete:^(NSMutableArray<Record *> * _Nonnull result) {
        self.array = result;
        [self.tableView reloadData];
    }];
}
#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ResultCell *cell = [tableView dequeueReusableCellWithIdentifier:[ResultCell ID]];
    cell.model = self.array[indexPath.row];
    cell.selectBtn.hidden = YES;
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 90;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 90)];
    view.backgroundColor = [UIColor clearColor];
    ResultHeader *header = (ResultHeader *)[ResultHeader loadFromXIB];
    header.frame = view.bounds;
    header.stamp = self.stamp;
    WS(self)
    header.block = ^(NSInteger stamp) {
        weakself.stamp = stamp;
    };
    [view addSubview:header];
    return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.title isEqualToString:LS(@"赛果")]){
        DetailViewController *vc = [DetailViewController new];
        vc.model = self.array[indexPath.section];
        [self push:vc :YES];
    }
    
}

@end

